<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Messages extends MX_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model(array('admin_commoncall','admin_settings_model','admin_messages_model','admin_counter_model','admin_listing_model'));

		//$this->admin_commoncall->check_admin_login();
		$this->load->library('pagination');
		$this->template->set_theme('admin');
		$this->template->set_layout('default');
		//$this->template->set_partial('side_menu','layouts/side_menu');
		//$this->template->set_partial('nav_bar','layouts/nav_bar');

	}

	function index()
	{

		$offset = 0 + $this->uri->segment(5);
		$config['base_url'] = base_url() . 'secure/reports/messages/index';
		$total = $this->admin_counter_model->count_all_messages('message');
		$perpage = 15;
		$config['per_page'] = $perpage;
		$config['total_rows'] = $total;
		$config['uri_segment'] = '5';

		$data['messages']['all'] = $this->admin_messages_model->get_all_messages($perpage, $offset);
		$this->pagination->initialize($config);


		if($this->input->post('search')){
			$search = 	trim($this->input->post('search'));
			$data['messages']['all'] = $this->admin_messages_model->search($search = $search);
			//print $search;
		}
		//var_dump($data['messages']['all']);
		//die();

		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		//->set_partial('footer', 'footer/footer')
		->build('reports/messages',$data);
	}

	function change_message_status($status=NULL,$id=NULL) {
		$this->admin_messages_model->change_status($id, $status);
		redirect('secure/reports/messages');
	}

	function delete_message($id){
		$this->admin_messages_model->delete($id);
		redirect('secure/reports/messages');
	}
	
	function message_view($id)
	{

		$data['message']['view'] = $this->admin_messages_model->get_message($id);

		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		//->set_partial('footer', 'footer/footer')
		->build('reports/message_view',$data);
	}

}